<template>
  <div>
      <h1>人员列表</h1>
      <input type="text" placeholder="请输入名字" v-model="name">
      <button @click="add">添加</button>
      <ul>
          <li v-for="p in personList" :key="p.id">{{p.name}}</li>
      </ul>
      <h3 style="color:red">求和放大10倍为：{{bigSum}}</h3>
  </div>
</template>

<script>
    import {nanoid} from 'nanoid'
    export default {
        name: 'Persion',
        computed: {
            bigSum() {
                return this.$store.getters.bigSum
            },
            personList() {
                return this.$store.state.personList
            }
        },
        data() {
            return {
                name: ''
            }
        },
        methods: {
            add() {
                const person = {id: nanoid(), name: this.name}
                this.$store.dispatch('addPerson', person)
                this.name = ''
            }
        }
    }
</script>

<style>

</style>